#include "MenuLayer.h"

MenuLayer::MenuLayer()
: pGameLayerManager(NULL)
{
}

MenuLayer::~MenuLayer()
{
}

MenuLayer * MenuLayer::create()
{
  MenuLayer *pLayer = new MenuLayer();
  if (pLayer && pLayer->init())
  {
    pLayer->autorelease();
    return pLayer;
  }
  else
  {
    CC_SAFE_DELETE(pLayer);
    return NULL;
  }
}

bool MenuLayer::init()
{
  do
  {
    CC_BREAK_IF(!CCLayer::init());
    CCLabelTTF *pPauseLabel = CCLabelTTF::create("PAUSE", "Arial", 40);
    CC_BREAK_IF(!pPauseLabel);
    CCMenuItemLabel * pPauseItemLabel = CCMenuItemLabel::create(pPauseLabel, this, menu_selector(MenuLayer::onPause));
    CC_BREAK_IF(!pPauseItemLabel);
    pPauseItemLabel->setPosition(ccp(540, 320));
    CCMenu * pMenu = CCMenu::create(pPauseItemLabel, NULL);
    CC_BREAK_IF(!pMenu);
    addChild(pMenu);
    return true;
  }while(0);
  return false;
}

void MenuLayer::setGameLayerManager(GameLayerManager * pGameLayerManager)
{
  this->pGameLayerManager = pGameLayerManager;
}

void MenuLayer::onPause(CCObject * pObj)
{
  this->pGameLayerManager->pauseGame();
}
